<!-- $Id: example-ajax.html,v 1.2 2006/04/27 21:00:38 pat Exp $ -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>::iSchedule::</title>

<link rel="stylesheet" href="style/tabber.css" TYPE="text/css" MEDIA="screen">


<script language="javascript1.2" type="text/javascript" src="./js/prototype.js"></script> 
	<script language="javascript1.2" type="text/javascript" src="./js/effects.js"></script> 
	<script language="javascript1.2" type="text/javascript" src="./js/controls.js"></script> 
	<script language="javascript1.2" type="text/javascript" src="./js/js.js"></script>
        <script language="javascript1.2" type="text/javascript" src="./js/Tokenizer.js"></script>

<script type="text/javascript">

document.write('<style type="text/css">.tabber{display:none;}<\/style>');

var tabberOptions = {

  'onClick': function(argsObj) {

    var t = argsObj.tabber; /* Tabber object */
    var i = argsObj.index; /* Which tab was clicked (0..n) */
    var div = this.tabs[i].div; /* The tab content div */
	
 
    /* Display a loading message */
    div.innerHTML = "<p>Loading...<\/p>";

    /* Fetch some html depending on which tab was clicked */
    var url = 'admin_forms/form' + i + '.html';
    var pars = ''; /* just for example */
    var myAjax = new Ajax.Updater(div, url, {method:'get',parameters:pars});
	
	if(i==2)
 		{
                    loadAllStudents();
 			//ajaxReadAvCourses();
 		}
  },

  'onLoad': function(argsObj) {
    /* Load the first tab */
    argsObj.index = 0;
    this.onClick(argsObj);
  },
}

function AJAXInteraction(url, callback) {

    var req = init();
    req.onreadystatechange = processRequest;
        
    function init() {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    
    function processRequest () {
      // readyState of 4 signifies request is complete
      if (req.readyState == 4) {
        // status of 200 signifies sucessful HTTP call
        if (req.status == 200) {
          if (callback) callback(req.responseXML);
        }
      }
    }

    this.doGet = function() {
      req.open("GET", url, true);
      req.send(null);
    }
}

function insertStudent() {
    var id = document.getElementById("sid");
    var name = document.getElementById("sname");
    var lastname1 = document.getElementById("sfirstLastName");
    var lastname2 = document.getElementById("ssecondLastName");
    
    var url = "AddStudent?id=" + encodeURIComponent(id.value) + "&" + "name=" + encodeURIComponent(name.value) + "&" + "firstLastName=" + encodeURIComponent(lastname1.value) + "&" + "secondLastName=" + encodeURIComponent(lastname2.value);    
    var target = document.getElementById("insertStudentMessage");
    var ajax = new AJAXInteraction(url, validateCallbackStudent);
    ajax.doGet();
}

function validateCallbackStudent(responseXML) {
   var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
   var mdiv = document.getElementById("insertStudentMessage");
   mdiv.innerHTML = msg;
   
    document.getElementById("sid").value = "";
    document.getElementById("sname").value = "";
    document.getElementById("sfirstLastName") = "";
    document.getElementById("ssecondLastName") = "";
}

function insertProfessor()
{
    var id = document.getElementById("pid");
    var name = document.getElementById("pname");
    var lastname1 = document.getElementById("pfirstLastName");
    var lastname2 = document.getElementById("psecondLastName");
    
    var url = "AddProfessor?id=" + encodeURIComponent(id.value) + "&" + "name=" + encodeURIComponent(name.value) + "&" + "firstLastName=" + encodeURIComponent(lastname1.value) + "&" + "secondLastName=" + encodeURIComponent(lastname2.value);
    var target = document.getElementById("insertProfessorMessage");
    var ajax = new AJAXInteraction(url, validateCallbackProfessor);
    ajax.doGet();
}

function validateCallbackProfessor(responseXML)
{
    var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    var mdiv = document.getElementById("insertProfessorMessage");
    mdiv.innerHTML = msg;
    
    document.getElementById("pid").value = "";
    document.getElementById("pname").value = "";
    document.getElementById("pfirstLastName") = "";
    document.getElementById("psecondLastName") = "";
}

function insertCourse()
{
    var name = document.getElementById("name");
    var code = document.getElementById("code");
    var professor = document.getElementById("professor");
    var classroom = document.getElementById("classroom");
    var ihour = document.getElementById("ihour");
    var ehour = document.getElementById("ehour");
    var days = document.getElementById("days");
    
    var url = "AddCourse?name=" + encodeURIComponent(name.value) + "&" + "code=" + encodeURIComponent(code.value) + "&" + "professor=" + encodeURIComponent(professor.value) + "&" + "classroom=" + encodeURIComponent(classroom.value) + "&" + "days=" + encodeURIComponent(days.value) + "&" + "hour=" + encodeURIComponent(ihour.value)+":"+encodeURIComponent(ehour.value);
    var ajax = new AJAXInteraction(url, validateCallbackCourses);
    ajax.doGet();
}

function validateCallbackCourses(responseXML)
{
    var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    var mdiv = document.getElementById("insertCourseMessage");
    mdiv.innerHTML = msg;
    
    document.getElementById("name").value = "";
    document.getElementById("code").value = "";
    document.getElementById("professor").value = "";
    document.getElementById("classroom").value = "";
    document.getElementById("ihour").value = "";
    document.getElementById("ehour").value = "";
    document.getElementById("days").value = "";
}

function insertClassroom()
{
    var building = document.getElementById("building");
    var number = document.getElementById("number");
    
    url = "AddClassroom?building=" + encodeURIComponent(building.value) + "&" + "number=" + encodeURIComponent(number.value);
    var ajax = new AJAXInteraction(url, validateCallbackClassrooms);
    ajax.doGet();
}

function validateCallbackClassrooms(responseXML)
{
   var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    var mdiv = document.getElementById("insertClassroomMessage");
    mdiv.innerHTML = msg;
    
    document.getElementById("building").value = "";
    document.getElementById("number").value = "";
}

function loadTeachers()
{
    var url = "GetAllProfessors";
    var ajax = new AJAXInteraction(url, validateCallbackLoadTeachers);
    ajax.doGet();
}

function loadClassrooms()
{
    var url = "GetAllClassrooms";
    var ajax = new AJAXInteraction(url, validateCallbackLoadClassrooms);
    ajax.doGet();
}

function validateCallbackLoadTeachers(responseXML)
{
    var contador = responseXML.getElementsByTagName('person').length;
    var index = 0;
    for (var i=0;i<=contador-1;i++)
    {	
        document.course_form.professor.options[index++] = new Option(responseXML.getElementsByTagName('person')[i].firstChild.nodeValue, responseXML.getElementsByTagName('person')[i].getAttribute('id'));			
    }
}


function validateCallbackLoadClassrooms(responseXML)
{
    var contador = responseXML.getElementsByTagName('classroom').length;
    var index = 0;
    for(var i=0; i<=contador-1; i++)
    {
        document.course_form.classroom.options[index++] = new Option(responseXML.getElementsByTagName('classroom')[i].firstChild.nodeValue, responseXML.getElementsByTagName('classroom')[i].getAttribute('id'));
    }
}

function listStudents()
{
    url = "GetAllStudents";
    var ajax = new AJAXInteraction(url, validateCallbackListStudents);
    ajax.doGet();
}

function listTeachers()
{
    url = "GetAllProfessors";
    var ajax = new AJAXInteraction(url, validateCallbackListTeachers);
    ajax.doGet();
}

function listCourses()
{
    url = "GetAllCourses";
    var ajax = new AJAXInteraction(url, validateCallbackListCourses);
    ajax.doGet();
}

function listClassrooms()
{
    url = "GetAllClassrooms";
    var ajax = new AJAXInteraction(url, validateCallbackListClassrooms);
    ajax.doGet();
}

function validateCallbackListStudents(responseXML)
{
    var Schedule="";
		
    Schedule += "<table width='800px'><tr><td width='100px'><strong>Student ID</strong></td><td width='250px'><strong>Student Name</strong></td><td width='50px'></td><td width='50px'></td><tr>";		
    var contador = responseXML.getElementsByTagName('person').length;
		
    for(var i=0;i<=contador-1;i++)
    {	
        var id = responseXML.getElementsByTagName('person')[i].getAttribute('id');
	Schedule += "<tr>";
	Schedule += "<td width='100px'>";
        Schedule += responseXML.getElementsByTagName('person')[i].getAttribute('id');
        Schedule += "</td>";
        Schedule += "<td width='250px'>";
        Schedule +=  responseXML.getElementsByTagName('person')[i].firstChild.data;
        Schedule += "</td>";
        Schedule += "<td width='50px'>";
        Schedule += "<img src='images/edit.png' width='22' height='22' onclick=\"edit('"+ id +"_edit_form','students');loadStudentById(" + id +  ");\">";
        Schedule += "</td>";
        Schedule += "<td width='50px'>";
        Schedule += "<img src='images/delete.png' width='22' height='22' onclick='deleteStudent(" + id + ");'>";
        Schedule += "</td><tr>";
        Schedule += "<td colspan='4'>";
        Schedule += "<div id='"+ responseXML.getElementsByTagName('person')[i].getAttribute('id') + "_edit_form'></div>";
        Schedule += "</td></tr>";
    };
    Schedule += "</table><br>";
    document.getElementById('list_st_div').innerHTML = Schedule;
    Effect.toggle('list_st_div','blind');
}

function validateCallbackListTeachers(responseXML)
{
    var Schedule="";
    
    Schedule += "<table width='800px'><tr><td width='100px'><strong>Professor ID</strong></td><td width='250px'><strong>Professor Name</strong></td><td width='50px'></td><td width='50px'></td>";

    var contador = responseXML.getElementsByTagName('person').length;

    for (var i=0;i<=contador-1;i++)
    {	
        var id = responseXML.getElementsByTagName('person')[i].getAttribute('id');
        Schedule += "<tr>";
        Schedule += "<td width='100px'>";
        Schedule += id;
        Schedule += "</td>";
        Schedule += "<td width='250px'>";
        Schedule += responseXML.getElementsByTagName('person')[i].firstChild.data;
        Schedule += "</td>";
        Schedule += "<td width='50px'>";
    Schedule += "<img src='images/edit.png' width='22' height='22' onclick=\"edit('"+ responseXML.getElementsByTagName('person')[i].getAttribute('id') +"_edit_form','professors');loadProfessorById(" + id + ");\">";
        Schedule += "</td>";
        Schedule += "<td width='50px'>";
        Schedule += "<img src='images/delete.png' width='22' height='22' onclick='deleteProfessor(" + id + ");'>";
        Schedule += "</td><tr>";
        Schedule += "<td colspan='4'>";
        Schedule += "<div id='"+ responseXML.getElementsByTagName('person')[i].getAttribute('id') + "_edit_form'></div>";
        Schedule += "</td></tr>";	
    };

        Schedule += "</table><br>";
                document.getElementById('list_teacher_div').innerHTML = Schedule;
                Effect.toggle('list_teacher_div','blind');
}

function validateCallbackListCourses(responseXML)
{
    var Schedule="";
		
    Schedule += "<table><tr><td width='250px'><strong>Course Name</strong></td><td width='100px'><strong>Time</strong></td><td width='100px'><strong>Days</strong></td><td width='100px'><strong>Classroom</strong></td><td width='150px'><strong>Professor</strong></td><td width='50px'></td><td width='50px'></td>";

    var contador = responseXML.getElementsByTagName('course').length;

    for (var i=0;i<=contador-1;i++)
    {	
        var id = responseXML.getElementsByTagName('course')[i].getAttribute('id');
        Schedule += "<tr>";
        Schedule += "<td>";
        Schedule += responseXML.getElementsByTagName('course')[i].firstChild.data;
        Schedule += "</td>";
        Schedule += "<td width='100px'>";
        Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('time');
        Schedule += "</td>";
        Schedule += "<td width='100px'>";
        Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('days');
        Schedule += "</td>";
        Schedule += "<td width='100px'>";
        Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('classroom');
        Schedule += "</td>";
        Schedule += "<td width='100px'>";
        Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('professor-name');
        Schedule += "</td>";
        Schedule += "<td width='50px'>";
        Schedule += "<img src='images/edit.png' width='22' height='22' onclick=\"edit('"+ responseXML.getElementsByTagName('course')[i].getAttribute('id') +"_edit_form','courses'," +  id + "); loadTeachersModify();loadClassroomsModify();loadCourseById(" + id + ");\">";
        Schedule += "</td>";
        Schedule += "<td width='50px'>";
        Schedule += "<img src='images/delete.png' width='22' height='22' onclick='deleteCourse(" + id + ");'>";
        Schedule += "</td><tr>";
        Schedule += "<td colspan='7'>";
        Schedule += "<div id='"+ responseXML.getElementsByTagName('course')[i].getAttribute('id') + "_edit_form'></div>";
        Schedule += "</td></tr>";
    }
        Schedule += "</table><br>";

    document.getElementById('list_course_div').innerHTML = Schedule;
    Effect.toggle('list_course_div','blind');
}

function validateCallbackListClassrooms(responseXML)
{
    	var Schedule="";
		
	Schedule += "<table width='800'><tr><td width='250px'><strong>ClassRoom</strong></td><td width='50px'></td><td width='50px'></td>";
		
	var contador = responseXML.getElementsByTagName('classroom').length;
		
	for (var i=0;i<=contador-1;i++)
			{
                        var id = responseXML.getElementsByTagName('classroom')[i].getAttribute('id');
				Schedule += "<tr>";
				Schedule += "<td width='250px'>";
				Schedule += responseXML.getElementsByTagName('classroom')[i].firstChild.data;
				Schedule += "</td>";
				Schedule += "<td width='50px'>";
				Schedule += "<img src='images/edit.png' width='22' height='22' onclick=\"edit('"+ responseXML.getElementsByTagName('classroom')[i].getAttribute('id') +"_edit_form','class'," + id +  "); loadClassroomById(" + id + ");\">";
				Schedule += "</td>";
				Schedule += "<td width='50px'>";
				Schedule += "<img src='images/delete.png' width='22' height='22' onclick='deleteClassroom(" + id + ");'>";
				Schedule += "</td><tr>";
				Schedule += "<td colspan='3'>";
				Schedule += "<div id='"+ responseXML.getElementsByTagName('classroom')[i].getAttribute('id') + "_edit_form'></div>";
				Schedule += "</td></tr>";	
			};
		
		Schedule += "</table><br>";
			document.getElementById('list_class_div').innerHTML = Schedule;
			Effect.toggle('list_class_div','blind');
}

function loadStudentById(id)
{
    url = "GetStudent?id=" + id;
    var ajax = new AJAXInteraction(url, validateCallbackLoadStudentById);
    ajax.doGet();
}

function validateCallbackLoadStudentById(responseXML)
{
    document.update_student_form.sid.value = responseXML.getElementsByTagName('id')[0].firstChild.nodeValue;
    document.update_student_form.sname.value = responseXML.getElementsByTagName('name')[0].firstChild.nodeValue; 
    document.update_student_form.sfirstLastName.value = responseXML.getElementsByTagName('firstLastName')[0].firstChild.nodeValue;
    document.update_student_form.ssecondLastName.value =  responseXML.getElementsByTagName('secondLastName')[0].firstChild.nodeValue;
    Effect.SlideDown(responseXML.getElementsByTagName('id')[0].firstChild.nodeValue);
}

function updateStudent()
{
    var id = document.update_student_form.sid;
    var name = document.update_student_form.sname;
    var lastname1 = document.update_student_form.sfirstLastName;
    var lastname2 = document.update_student_form.ssecondLastName;
    
    var url = "ModifyStudent?id=" + id.value + "&" + "name=" + name.value + "&" + "firstLastName=" + lastname1.value + "&" + "secondLastName=" + lastname2.value;    
    var target = document.getElementById("modifyStudentMessage");
    var ajax = new AJAXInteraction(url, validateCallbackModifyStudent);
    ajax.doGet();
}

function validateCallbackModifyStudent(responseXML) {
   var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
   var mdiv = document.getElementById("modifyStudentMessage");
   mdiv.innerHTML = msg;
}


function deleteStudent(id)
{
    var url = "DeleteStudent?id=" + id;
    var ajax = new AJAXInteraction(url, validateCallbackDeleteStudent);
    ajax.doGet();
}

function validateCallbackDeleteStudent(responseXML)
{
    var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    alert(msg);
    Effect.toggle('list_st_div','blind');
}


function loadProfessorById(id)
{
    var url = "GetProfessor?id=" + id;
    var ajax = new AJAXInteraction(url, validateCallbackLoadProfessorById);
    ajax.doGet();
}

function validateCallbackLoadProfessorById(responseXML)
{
    document.update_professor_form.pid.value = responseXML.getElementsByTagName('id')[0].firstChild.nodeValue;
    document.update_professor_form.pname.value = responseXML.getElementsByTagName('name')[0].firstChild.nodeValue; 
    document.update_professor_form.pfirstLastName.value = responseXML.getElementsByTagName('firstLastName')[0].firstChild.nodeValue;
    document.update_professor_form.psecondLastName.value =  responseXML.getElementsByTagName('secondLastName')[0].firstChild.nodeValue;
    Effect.SlideDown(responseXML.getElementsByTagName('id')[0].firstChild.nodeValue);
}

function updateProfessor()
{
    var id = document.update_professor_form.pid;
    var name = document.update_professor_form.pname;
    var lastname1 = document.update_professor_form.pfirstLastName;
    var lastname2 = document.update_professor_form.psecondLastName;
    
    var url = "ModifyProfessor?id=" + id.value + "&" + "name=" + name.value + "&" + "firstLastName=" + lastname1.value + "&" + "secondLastName=" + lastname2.value;    
    var target = document.getElementById("modifyProfessorMessage");
    var ajax = new AJAXInteraction(url, validateCallbackModifyProfessor);
    ajax.doGet();
}

function validateCallbackModifyProfessor(responseXML)
{
    var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    var mdiv = document.getElementById("modifyProfessorMessage");
    mdiv.innerHTML = msg;
}

function deleteProfessor(id)
{
    var url = "DeleteProfessor?id=" + id;
    var ajax = new AJAXInteraction(url, validateCallbackDeleteProfessor);
    ajax.doGet();
}

function validateCallbackDeleteProfessor(responseXML)
{
    var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    alert(msg);
    Effect.toggle('list_teacher_div','blind');
}

function loadCourseById(id)
{
    var url = "GetCourse?id=" + id;
    var ajax = new AJAXInteraction(url, validateCallbackLoadCourseById);
    ajax.doGet();
}


function validateCallbackLoadCourseById(responseXML)
{

    document.update_course_form.code.value = responseXML.getElementsByTagName('code-course')[0].firstChild.nodeValue;
    document.update_course_form.name.value = responseXML.getElementsByTagName('title')[0].firstChild.nodeValue; 
    document.update_course_form.days.value = responseXML.getElementsByTagName('days')[0].firstChild.nodeValue;
    
    var time = responseXML.getElementsByTagName('hour')[0].firstChild.nodeValue;
    var tokens = time.tokenize("-", true);
    
    document.update_course_form.shour.value = tokens[0];
    document.update_course_form.ehour.value = tokens[1];
    
    
    var idp = responseXML.getElementsByTagName('professor')[0].getAttribute('id');
    var idc = responseXML.getElementsByTagName('classroom')[0].getAttribute('id');
    var index = 0;
    var indexp = -1;
    var indexc = -1;
    for (var i=0;i<document.update_course_form.professor.options.length;i++)
    {	
        if(document.update_course_form.professor.options[i].value == idp)
        {
            indexp = i;
            break;  
        }
    }
    
    for (var i=0;i<document.update_course_form.classroom.options.length;i++)
    {	
        if(document.update_course_form.classroom.options[i].value == idc)
        {
            indexc = i;
            break;  
        }
    }
    
    document.update_course_form.professor.selectedIndex = indexp;
    document.update_course_form.classroom.selectedIndex = indexc;
    Effect.SlideDown(responseXML.getElementsByTagName('id')[0].firstChild.nodeValue);
}

function loadTeachersModify()
{
    var url = "GetAllProfessors";
    var ajax = new AJAXInteraction(url, validateCallbackLoadTeachersModify);
    ajax.doGet();
}

function loadClassroomsModify()
{
    var url = "GetAllClassrooms";
    var ajax = new AJAXInteraction(url, validateCallbackLoadClassroomsModify);
    ajax.doGet();
}

function validateCallbackLoadTeachersModify(responseXML)
{
    var contador = responseXML.getElementsByTagName('person').length;
    var index = 0;
    for (var i=0;i<=contador-1;i++)
    {	
        document.update_course_form.professor.options[index++] = new Option(responseXML.getElementsByTagName('person')[i].firstChild.nodeValue, responseXML.getElementsByTagName('person')[i].getAttribute('id'));			
    }
}


function validateCallbackLoadClassroomsModify(responseXML)
{
    var contador = responseXML.getElementsByTagName('classroom').length;
    var index = 0;
    for(var i=0; i<=contador-1; i++)
    {
        document.update_course_form.classroom.options[index++] = new Option(responseXML.getElementsByTagName('classroom')[i].firstChild.nodeValue, responseXML.getElementsByTagName('classroom')[i].getAttribute('id'));
    }
}

function updateCourse(id)
{
    var name = document.update_course_form.name;
    var code = document.update_course_form.code;
    var professor = document.update_course_form.professor;
    var classroom = document.update_course_form.classroom;
    var shour = document.update_course_form.shour;
    var ehour = document.update_course_form.ehour;
    var days = document.update_course_form.days;
    
    var url = "ModifyCourse?id=" + id + "&" + "name=" + name.value + "&" + "code=" + code.value + "&" + "professor=" + professor.value + "&" + "classroom=" + classroom.value + "&" + "days=" + days.value + "&" + "hour=" + shour.value+":"+ehour.value;
    var ajax = new AJAXInteraction(url, validateCallbackModifyCourse);
    ajax.doGet();
}

function validateCallbackModifyCourse(responseXML)
{
    var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    var mdiv = document.getElementById("modifyCourseMessage");
    mdiv.innerHTML = msg;
}

function deleteCourse(id)
{
    var url = "DeleteCourse?id=" + id;
    var ajax= new AJAXInteraction(url, validateCallbackDeleteCourse);
    ajax.doGet();
}

function validateCallbackDeleteCourse(responseXML)
{
    var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    alert(msg);
    Effect.toggle('list_course_div','blind');
}

function loadClassroomById(id)
{
    var url = "GetClassroom?id=" + id;
    var ajax = new AJAXInteraction(url, validateCallbackLoadClassroomById);
    ajax.doGet();
}

function validateCallbackLoadClassroomById(responseXML)
{
    document.update_classroom_form.building.value = responseXML.getElementsByTagName('building')[0].firstChild.nodeValue;
    document.update_classroom_form.number.value = responseXML.getElementsByTagName('number')[0].firstChild.nodeValue; 
    Effect.SlideDown(responseXML.getElementsByTagName('id')[0].firstChild.nodeValue);
}

function updateClassroom(id)
{
    var building = document.update_classroom_form.building;
    var number = document.update_classroom_form.number;
    
    var url = "ModifyClassroom?id=" + id + "&" + "building=" + building.value + "&" + "number=" + number.value;    
    var target = document.getElementById("modifyProfessorMessage");
    var ajax = new AJAXInteraction(url, validateCallbackModifyClassroom);
    ajax.doGet();
}

function validateCallbackModifyClassroom(responseXML)
{
    var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    var mdiv = document.getElementById("modifyClassroomMessage");
    mdiv.innerHTML = msg;
}

function deleteClassroom(id)
{
    var url = "DeleteClassroom?id=" + id;
    var ajax= new AJAXInteraction(url, validateCallbackDeleteClassroom);
    ajax.doGet();
}

function validateCallbackDeleteClassroom(responseXML)
{
    var msg = responseXML.getElementsByTagName("message")[0].firstChild.nodeValue;
    alert(msg);
    Effect.toggle('list_classroom_div','blind');
}

function loadAllStudents()
{
    
    var url = "GetAllStudents";
    var ajax = new AJAXInteraction(url, validateCallbackLoadStudentsSchedule);
    ajax.doGet();
}

function validateCallbackLoadStudentsSchedule(responseXML)
{
    var contador = responseXML.getElementsByTagName('person').length;
    var index = 0;
    for (var i=0;i<=contador-1;i++)
    {	
        document.search_student.name.options[index++] = new Option(responseXML.getElementsByTagName('person')[i].firstChild.nodeValue, responseXML.getElementsByTagName('person')[i].getAttribute('id'));			
    }
}

function loadStudentSchedule()
{
    var id = document.search_student.name.value;
    var url = "SearchNotRegisteredCourses?student_id=" + id;
    alert(url);
    var ajax = new AJAXInteraction(url, validateCallbackLoadStudentsSchedules);
    ajax.doGet();
}

function validateCallbackLoadStudentsSchedules(responseXML)
{
    var Schedule="";
		
		Schedule += "<br><br><div style=\"width:300px;float:left;\"><strong>Course Name</strong></div><div style=\"width:100px;float:left;\"><strong>Days</strong></div><div style=\"width:120px;float:left;\"><strong>Time</strong></div><div style=\"width:130px;float:left;\"><strong>Classroom</strong></div><div style=\"width:200px;float:left;\"><strong>Professor</strong></div><div style=\"width:100px;float:left;\"></div><br><br>";
		
		var contador = responseXML.getElementsByTagName('course').length;
		
		for (var i=0;i<=contador-1;i++)
			{	
                                var id = responseXML.getElementsByTagName('course')[i].getAttribute('id');
				Schedule += "<div id='"+ responseXML.getElementsByTagName('course')[i].getAttribute('id') + "arriba" +"'>"
				Schedule += "<div style=\"width:300px;float:left;\" >";
				Schedule += responseXML.getElementsByTagName('course')[i].firstChild.data;
				Schedule += "</div>";
				Schedule += "<div style=\"width:100px;float:left;\" >";
				Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('days');
				Schedule += "</div>";
				Schedule += "<div style=\"width:120px;float:left;\" >";
				Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('time');
				Schedule += "</div>";
				Schedule += "<div style=\"width:130px;float:left;\" >";
				Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('classroom');
				Schedule += "</div>";
				Schedule += "<div style=\"width:200px;float:left;\" >";
				Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('professor-name');
				Schedule += "</div>";
				Schedule += "<div style=\"width:100px;float:left;\" >";
				Schedule += "<a href='javascript:;' onclick=\"inscribir('";
				Schedule += responseXML.getElementsByTagName('course')[i].firstChild.data;
				Schedule += "','" + responseXML.getElementsByTagName('course')[i].getAttribute('days');
				Schedule += "','" + responseXML.getElementsByTagName('course')[i].getAttribute('time');
				Schedule += "','" + responseXML.getElementsByTagName('course')[i].getAttribute('classroom');
				Schedule += "','" + responseXML.getElementsByTagName('course')[i].getAttribute('professor-name');
				Schedule += "','" + responseXML.getElementsByTagName('course')[i].getAttribute('id');
                                Schedule += "'),addStudentCourse(" + id + ");new Effect.SwitchOff('"+ responseXML.getElementsByTagName('course')[i].getAttribute('id') + "arriba" +"');\">inscribir</a>";
				Schedule += "</div></div><br>";
			}
                	document.getElementById('courses_list').innerHTML = Schedule;
}

var lista = "";
function inscribir(course, days, time, classroom, professor_name, id)
{	
        lista = "";
        lista += "<div id='" + id  + "abajo" + "'>";
	lista += "<div style=\"width:300px;float:left;\">";
	lista += course;
	lista += "</div>";
	lista += "<div style=\"width:100px;float:left;\">";
	lista += days;
	lista += "</div>";
	lista += "<div style=\"width:120px;float:left;\">";
	lista += time;
	lista += "</div>";
	lista += "<div style=\"width:130px;float:left;\">";
	lista += classroom;
	lista += "</div>";
	lista += "<div style=\"width:200px;float:left;\">";
	lista += professor_name;
        lista += "</div>";
	lista += "<div style=\"width:100px;float:left;\"><a href='javascript:;' onclick=\"borrar(";
        lista += "'" + course + "'" + ",";
        lista += "'" + days + "'" + ",";
        lista += "'" + time + "'" + ",";
        lista += "'" + classroom + "'" + ",";
        lista += "'" + professor_name + "'" + ",";
        lista += "'" + id + "'";
        lista += ");deleteStudentCourse(" + id + ");new Effect.SwitchOff('"+ id + "abajo" + "');\">borrar</a></div>";
        lista += "</div>";
        lista += "<br>";
        alert(lista);
			document.getElementById('new_list').innerHTML += lista
}
        
var lista2 = "";
function borrar(course, days, time, classroom, professor_name, id)
{
    lista2 = "";
        lista2 += "<div id='" + id  + "arriba" + "'>";
	lista2 += "<div style=\"width:300px;float:left;\">";
	lista2 += course;
	lista2 += "</div>";
	lista2 += "<div style=\"width:100px;float:left;\">";
	lista2 += days;
	lista2 += "</div>";
	lista2 += "<div style=\"width:120px;float:left;\">";
	lista2 += time;
	lista2 += "</div>";
	lista2 += "<div style=\"width:130px;float:left;\">";
	lista2 += classroom;
	lista2 += "</div>";
	lista2 += "<div style=\"width:200px;float:left;\">";
	lista2 += professor_name;
        lista2 += "</div>";
	lista2 += "<div style=\"width:100px;float:left;\"><a href='javascript:;' onclick=\"inscribir(";
        lista2 += "'" + course +  "'" +  ",";
        lista2 += "'" + days + "'" + ",";
        lista2 += "'" + time + "'" + ",";
        lista2 += "'" + classroom + "'" +  ",";
        lista2 += "'" + professor_name + "'" +  ",";
        lista2 += "'" + id + "'";
        lista2 += ");addStudentCourse(" + id + ");new Effect.SwitchOff('"+ id + "arriba" + "');\">inscribir</a></div>";
        lista2 += "</div>";
        lista2 += "<br>";
        
			document.getElementById('old_new_list').innerHTML += lista2;
	
}

function loadStudentActualCourses()
{
    var id = document.search_student.name.value;
    var url = "SearchStudentSchedule?student_id=" + id;
    document.getElementById('choose_list').innerHTML = "";
    document.getElementById('new_list').innerHTML = "";
    document.getElementById('old_new_list').innerHTML="";
    lista = "";
    lista2 = "";
    var ajax = new AJAXInteraction(url, validateCallbackLoadStudentActualCourses);
    ajax.doGet();
}

function validateCallbackLoadStudentActualCourses(responseXML)
{
    
    var Schedule="";
		
		Schedule += "Cursos Inscritos<br><br><div style=\"width:300px;float:left;\"><strong>Course Name</strong></div><div style=\"width:100px;float:left;\"><strong>Days</strong></div><div style=\"width:120px;float:left;\"><strong>Time</strong></div><div style=\"width:130px;float:left;\"><strong>Classroom</strong></div><div style=\"width:200px;float:left;\"><strong>Professor</strong></div><br><br>";
		
		var contador = responseXML.getElementsByTagName('course').length;
		
		for (var i=0;i<=contador-1;i++)
			{	
                                var id = responseXML.getElementsByTagName('course')[i].getAttribute('id');
				Schedule += "<div id='"+ responseXML.getElementsByTagName('course')[i].getAttribute('id') + "abajo"  +"'>"
				Schedule += "<div style=\"width:300px;float:left;\" >";
				Schedule += responseXML.getElementsByTagName('course')[i].firstChild.data;
				Schedule += "</div>";
				Schedule += "<div style=\"width:100px;float:left;\" >";
				Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('days');
				Schedule += "</div>";
				Schedule += "<div style=\"width:120px;float:left;\" >";
				Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('time');
				Schedule += "</div>";
				Schedule += "<div style=\"width:130px;float:left;\" >";
				Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('classroom');
				Schedule += "</div>";
				Schedule += "<div style=\"width:200px;float:left;\" >";
				Schedule += responseXML.getElementsByTagName('course')[i].getAttribute('professor-name');
				Schedule += "</div>";
				Schedule += "<div style=\"width:100px;float:left;\"> <a href='javascript:;' onclick=\"borrar('";
                                Schedule += responseXML.getElementsByTagName('course')[i].firstChild.data;
				Schedule += "','" + responseXML.getElementsByTagName('course')[i].getAttribute('days');
				Schedule += "','" + responseXML.getElementsByTagName('course')[i].getAttribute('time');
				Schedule += "','" + responseXML.getElementsByTagName('course')[i].getAttribute('classroom');
				Schedule += "','" + responseXML.getElementsByTagName('course')[i].getAttribute('professor-name');
				Schedule += "','" + responseXML.getElementsByTagName('course')[i].getAttribute('id');
                                Schedule += "'),deleteStudentCourse(" + id + ");new Effect.SwitchOff('"+ responseXML.getElementsByTagName('course')[i].getAttribute('id') + "abajo" + "');\">borrar</a></div>";
                                Schedule +="</div><br>";
			}
                	document.getElementById('choose_list').innerHTML = Schedule;
}


function addStudentCourse(id)
{
    var student_id = document.search_student.name.value;
    
    url = "AddSchedule?student_id=" + student_id + "&" + "course_id=" + id;
    alert(url);
    var ajax = new AJAXInteraction(url, validateCallbackAddStudentCourse);
    ajax.doGet();
}

function validateCallbackAddStudentCourse(responseXML)
{
}

function deleteStudentCourse(id)
{
    var student_id = document.search_student.name.value;
    
    url = "DeleteSchedule?student_id=" + student_id + "&" + "course_id=" + id;
    alert(url);
    var ajax = new AJAXInteraction(url, validateCallbackDeleteStudentCourse);
    ajax.doGet();
}

function validateCallbackDeleteStudentCourse(responseXML)
{
}

</script>

<script type="text/javascript" src="js/tabber.js"></script>

<style type="text/css">
.tabberlive .tabbertab {
  height:auto;
}
</style>
<link href="style/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="logo_little"><img src="images/ischedule_logo_little.png" width="200" height="55"></div>
<h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Admin<div id="st_div"> </div></h1>

<div class="tabber">

     <div class="tabbertab">
	  <h2>Add</h2>
     </div>


     <div class="tabbertab">
	  <h2>Manage</h2>
     </div>


	 <div class="tabbertab">
	  <h2>Add Student Schedule </h2>
     </div>

</div>

</body>
</html>
